package com.edu.exam.entity.assessment.technical;

import com.edu.exam.enums.assessment.technical.QualityStandardStatus;
import com.edu.exam.enums.exam.ExamType;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 质量标准实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：quality_standard
 *
 * 根据E-06-03质量监控子模块设计实现
 * 对应quality_standards数据表，用于存储质量标准的定义和配置信息
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Accessors(chain = true)
public class QualityStandard {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "standard_id", length = 32, unique = true, nullable = false)
    private String standardId;

    @Column(name = "standard_name", length = 100, nullable = false)
    private String standardName;

    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    @Enumerated(EnumType.STRING)
    @Column(name = "exam_type", length = 20, nullable = false)
    private ExamType examType;

    @Column(name = "version", length = 10, nullable = false)
    private String version;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 20, nullable = false)
    private QualityStandardStatus status;

    @Column(name = "criteria_config", columnDefinition = "JSON", nullable = false)
    private String criteriaConfig;

    @Column(name = "scoring_rules", columnDefinition = "JSON", nullable = false)
    private String scoringRules;

    @Column(name = "created_by", length = 32, nullable = false)
    private String createdBy;

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_by", length = 32)
    private String updatedBy;

    @UpdateTimestamp
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;

    // 扩展字段
    @Column(name = "category", length = 50)
    private String category; // 标准分类

    @Column(name = "sub_category", length = 50)
    private String subCategory; // 子分类

    @Column(name = "priority", length = 20)
    private String priority; // 优先级

    @Column(name = "effective_date")
    private LocalDateTime effectiveDate; // 生效日期

    @Column(name = "expiry_date")
    private LocalDateTime expiryDate; // 过期日期

    @Column(name = "application_scope", length = 100)
    private String applicationScope; // 应用范围

    @Column(name = "target_modules", columnDefinition = "JSON")
    private String targetModules; // 目标模块（JSON数组）

    @Column(name = "quality_threshold", precision = 5, scale = 2)
    private Double qualityThreshold; // 质量阈值

    @Column(name = "minimum_score", precision = 5, scale = 2)
    private Double minimumScore; // 最低分数

    @Column(name = "maximum_score", precision = 5, scale = 2)
    private Double maximumScore; // 最高分数

    @Column(name = "weight_config", columnDefinition = "JSON")
    private String weightConfig; // 权重配置

    @Column(name = "evaluation_methods", columnDefinition = "JSON")
    private String evaluationMethods; // 评估方法

    @Column(name = "validation_rules", columnDefinition = "JSON")
    private String validationRules; // 验证规则

    @Column(name = "exception_handling", columnDefinition = "JSON")
    private String exceptionHandling; // 异常处理规则

    @Column(name = "escalation_rules", columnDefinition = "JSON")
    private String escalationRules; // 升级规则

    @Column(name = "review_required")
    private Boolean reviewRequired; // 是否需要审查

    @Column(name = "reviewed_by", length = 32)
    private String reviewedBy; // 审查人

    @Column(name = "review_time")
    private LocalDateTime reviewTime; // 审查时间

    @Column(name = "review_comments", columnDefinition = "TEXT")
    private String reviewComments; // 审查意见

    @Column(name = "approved_by", length = 32)
    private String approvedBy; // 审批人

    @Column(name = "approval_time")
    private LocalDateTime approvalTime; // 审批时间

    @Column(name = "approval_status", length = 20)
    private String approvalStatus; // 审批状态

    @Column(name = "tags", length = 500)
    private String tags; // 标签（逗号分隔）

    @Column(name = "notes", columnDefinition = "TEXT")
    private String notes; // 备注

    @Column(name = "usage_count")
    private Long usageCount; // 使用次数

    @Column(name = "last_used_time")
    private LocalDateTime lastUsedTime; // 最后使用时间

    @Column(name = "average_score", precision = 5, scale = 2)
    private Double averageScore; // 平均得分

    @Column(name = "compliance_rate", precision = 5, scale = 2)
    private Double complianceRate; // 合规率

    @Column(name = "effectiveness_rating", precision = 3, scale = 2)
    private Double effectivenessRating; // 效果评级
}